package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ThresholdValue;
import com.ruoyi.system.service.IThresholdValueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 阈值Controller
 *
 * @author ruoyi
 * @date 2023-10-08
 */
@RestController
@RequestMapping("/system/value")
public class ThresholdValueController extends BaseController
{
    @Autowired
    private IThresholdValueService thresholdValueService;

    /**
     * 查询阈值列表
     */
    @PreAuthorize("@ss.hasPermi('system:value:list')")
    @GetMapping("/list")
    public TableDataInfo list(ThresholdValue thresholdValue)
    {
//        startPage();
        List<ThresholdValue> list = thresholdValueService.selectThresholdValueList(thresholdValue);
        return getDataTable(list);
    }

    /**
     * 导出阈值列表
     */
    @PreAuthorize("@ss.hasPermi('system:value:export')")
    @Log(title = "阈值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ThresholdValue thresholdValue)
    {
        List<ThresholdValue> list = thresholdValueService.selectThresholdValueList(thresholdValue);
        ExcelUtil<ThresholdValue> util = new ExcelUtil<ThresholdValue>(ThresholdValue.class);
        util.exportExcel(response, list, "阈值数据");
    }

    /**
     * 获取阈值详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:value:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(thresholdValueService.selectThresholdValueById(id));
    }

    /**
     * 新增阈值
     */
    @PreAuthorize("@ss.hasPermi('system:value:add')")
    @Log(title = "阈值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ThresholdValue thresholdValue)
    {
        return toAjax(thresholdValueService.insertThresholdValue(thresholdValue));
    }

    /**
     * 修改阈值
     */
    @PreAuthorize("@ss.hasPermi('system:value:edit')")
    @Log(title = "阈值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ThresholdValue thresholdValue)
    {
        return toAjax(thresholdValueService.updateThresholdValue(thresholdValue));
    }

    /**
     * 删除阈值
     */
    @PreAuthorize("@ss.hasPermi('system:value:remove')")
    @Log(title = "阈值", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(thresholdValueService.deleteThresholdValueByIds(ids));
    }
}
